package apps.softtech.fastmarket.adapter;

import java.util.ArrayList;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import apps.softtech.Utility.ApplicationConstants;
import apps.softtech.Utility.BitmapManager;
import apps.softtech.fastmarket.R;
import apps.softtech.fastmarket.model.Product;

public class AdapterProductList extends BaseAdapter{

	ArrayList<Product> mProductsList = new ArrayList<Product>();
	LayoutInflater inf;
	Context mContext;
	BitmapManager mBitmapManager;
	DisplayImageOptions options;
	public AdapterProductList(ArrayList<Product> mProductsList, Context mContext,DisplayImageOptions options){
		this.mContext = mContext;
		this.mProductsList = mProductsList;
		inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.options = options;
	}
	@Override
	public int getCount() {
//		return 30;
		return mProductsList.size();//
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}
	@Override
	public View getView(int position, View vi, ViewGroup arg2) {
		ViewHolder vh =null;
		if(vi==null){
			vi = inf.inflate(R.layout.item_product_list, null);
			vh = new ViewHolder();
			vh.ivProduct = (ImageView)vi.findViewById(R.id.ivProductList);
			
			vh.tvProductName = (TextView)vi.findViewById(R.id.tvProductName);
			
			vh.tvProductSale = (TextView)vi.findViewById(R.id.tvProductSale);
			
			vi.setTag(vh);
		}else{
			vh = (ViewHolder) vi.getTag();
		}
			//get name
			vh.tvProductName.setText(""+mProductsList.get(position).getProductName());
			//get sale
			vh.tvProductSale.setText(""+mProductsList.get(position).getPrice());
			
			ImageLoader.getInstance().displayImage(ApplicationConstants.BASE_URL_IMAGE + mProductsList.get(position).getAvatarPath(), vh.ivProduct
					,options);
		
		return vi;
	}
	class ViewHolder{
		
		ImageView ivProduct;
		
		TextView tvProductName;
		
		TextView tvProductSale;
	}
	

}
